# -*- encoding: utf-8 -*-

# Copyright 2010 István Szentandrási
# <etude-music-player@googlegroups.com>

# This file is part of Etude.
#
# Etude is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as 
# published by the Free Software Foundation, either version 3 
# of the License, or (at your option) any later version.
#
# Etude is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Etude. If not, see <http://www.gnu.org/licenses/>.

from . import _

import etude.plugins as ep
import dbus_util


class DBusPlugin(ep.PluginExtra):

    """
    DBus plugin for allowing communication through DBus.
    It allows only one active instance of Etude.
    """
    _short_name = "DBus plugin"
    _show_name = _("DBus plugin")
    _short_descr = _("One active instance, communication with Etude through DBus.")
    _version = "0.1"
    _unique = "DBus_plugin-0.1" # short name + version is enough, just to identify loaded

    def __init__(self, control):
        ep.PluginExtra.__init__(self, control)
        if dbus_util.using_dbus():
            self.etude_dbus = dbus_util.EtudeDBus(self.show_h, self.toggle_h, self.popup_h)
            dbus_util.start_dbus_interface()

    def show_h(self, data=None):
        self.control.layout.show_main()

    def toggle_h(self, data=None):
        self.control.layout.toggle_main()

    def popup_h(self, data=None):
        if self.control.has_interface('show_notify'):
            self.control.use_interface('show_notify')

